﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using xplang.run;
using xplang.abstractions;
using xplang.contexts;
using xplang.errors;

namespace xplang.parse
{

  public delegate CompilerForFiles GetCompiler(SourceReader source, Context context, Token name);

  public abstract class CompilerForFiles : Compiler
  {

    public CompilerForFiles(SourceReader source, Object declaring)
    {
      this.source = source;
      this.declaring = declaring;
    }

    public readonly SourceReader source;
    public readonly Object declaring;

    public abstract void compileRequirements();
    public abstract void compileDeclarations();
    public abstract void compileImplementations();

    public override void nextToken()
    {
      source.nextToken();
      current = source.current;
    }

    private int compilestate = 0;
    public void compile(int state)
    {
      if (state >= 1 && this.compilestate == 0)
      {
        compileRequirements();
        compilestate = 1;
      }
      if (state >= 2 && this.compilestate == 1)
      {
        compileDeclarations();
        compilestate = 2;
      }
      if (state >= 3 && this.compilestate == 2)
      {
        compileImplementations();
        compilestate = 3;
      }
    }
  }
}
